{% extends 'users/user_profile.html' %}

{% block title %}
  <li class="is-active"><a>编辑用户</a></li> 
{% endblock %}

{% block content %}
<form action="{% url 'users:editor_users' %}" method="post" enctype="multipart/form-data">
    {% csrf_token %}
    
    <!-- 用户表单 -->
    <div class="field">
        <label for="{{ form.email.id_for_label }}" class="label">{{ form.email.label }}</label>
        <div class="control">
            {{ form.email }}
            {% if form.email.errors %}
                <p class="help is-danger">{{ form.email.errors }}</p>
            {% endif %}
        </div>
    </div>
    
    <!-- 用户个人资料表单 -->
    {% for field in user_profile_form %}
    <div class="field">
        <label class="label" for="{{ field.id_for_label }}">{{ field.label }}</label>
        <div class="control">
            {% if field.name == 'gender' %}
                <div class="select is-medium">
                    {{ field }}
                </div>
            {% elif field.field.widget.input_type == 'file' %}
                <div class="file">
                    <label class="file-label">
                        <input class="file-input" type="file" name="{{ field.html_name }}">
                        <span class="file-cta">
                            <span class="file-icon">
                                <i class="fas fa-upload"></i>
                            </span>
                            <span class="file-label"> Choose a file… </span>
                        </span>
                    </label>
                </div>
            {% elif field.name == 'birthday' %}
                <input type="date" class="input is-medium" id="{{ field.id_for_label }}" name="{{ field.html_name }}" value="{{ field.value|date:'Y-m-d' }}">
            {% else %}
                <input type="{{ field.field.widget.input_type }}" class="input is-medium" id="{{ field.id_for_label }}" name="{{ field.html_name }}" {% if field.field.required %}required{% endif %} value="{{ field.value|default:'' }}">
            {% endif %}
            {% if field.errors %}
                <p class="help is-danger">{{ field.errors }}</p>
            {% endif %}
        </div>
    </div>
    {% endfor %}
    
    <div class="field is-grouped">
        <div class="control">
            <button class="button is-primary" type="submit">保存修改</button>
        </div>
    </div>
</form>
{% endblock %}
